#!/usr/bin/env python
# coding:utf-8
import unittest
import json
from sql_rice.gui.engine import create_widget_info, TEXT

class TestControls(unittest.TestCase):

    def setUp(self):
        strdict = '''
        {
            "empleados":{ 
                "rut":{
                    "default": null,
                    "not_null": 0,
                    "pk": 0,
                    "type": "text",
                    "length": 12
                    },
                 "nombre":{
                    "default": null,
                    "not_null": 0,
                    "pk": 0,
                    "type": "text",
                    "length": 0
                },
                "edad":{
                    "default": null,
                    "not_null": 0,
                    "pk": 0,
                    "type": "natural",
                    "length": 0
                }
            }
        }'''
        self.data_dict = json.loads(strdict)
        
    def test_create_control_rule(self):
        r = create_widget_info('rut', 'empleados', self.data_dict)
        self.assertEqual(r['name'], 'rut')
        self.assertEqual(r['rules']['maxLength'],{'length': 12})
        self.assertEqual(r['widget'], TEXT)

